// components/Card/Card.js
import request from '../../utils/request.js'
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    categoryId:{
      type:String,
      value:'categoryId',
      observer(nv, ov, path) {
        // console.log('nv',nv);
        if (nv) {
          // this.setData({
          //   categoryId: nv,
          // })
          // // console.log(nv,'2222');
          // console.log(this.data.categoryId,'11111');
          this.getCategoryList(nv)
        }
      }
    },
  },

  /**
   * 页面的初始数据
   */
  data: {
    bannerList:[],
    categoryItemList:[],
    categoryId:null,
  },

  attached:function(){
    // const categoryId = this.properties.categoryId
    // console.log(categoryId);
    // this.setData({
    //   categoryId
    // })
    this.getCategoryList()
  },

  
   /**
   * 组件的方法列表
   */
  methods: {
    getCategoryList(categoryId){
      // console.log(this.data.categoryId);
      request("/item/list.json",{categoryId})
      .then((result) => {
        // console.log(result);
        const categoryItemList = result.data?.categoryItemList || []
        const bannerList = (result.data?.currentCategory || {}).bannerList || []
        this.setData({
          categoryItemList,
          bannerList,
        })
      })
    },
  }

})